import React, { Component } from 'react';

const delay = ms => new Promise(r => setTimeout(r, ms));

async function afterOneSecond(callback) {
  await delay(1000).then(callback);
}

async function afterTwoSecond(callback) {
  await delay(2000).then(callback);
}

export default class Greet extends Component {
  state = {
    text: 'hi',
  };

  componentDidMount() {
    console.log(1);
    afterTwoSecond(() => {
      this.setState({ text: 'two second' });
      console.log(5);
    });
    console.log(2);
    afterOneSecond(() => {
      this.setState({ text: 'one second' });
      console.log(4);
    });

    console.log(3);
  }
  render() {
    return <div>{this.state.text}</div>;
  }
}
